{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#1. 首先需要通过API Key和Secret Key获取access_token"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.6d847ce79f0d599b7c412dc48b5b8c98.315360000.1926568038.282335-23570374', 'expires_in': 2592000, 'session_key': '9mzdWTwzeVL/uwdgcdfR5TZn60NBUm/vsgikXegVLPsPKiNeJnpAG4QxoDrm7eCYlRykgOV0p9Y6HWVggJrgzmnCX0Juwg==', 'access_token': '24.bf5bbb6757ed8399c279b09bfae5ba54.2592000.1613800038.282335-23570374', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient vis-faceverify_faceverify_h5-face-liveness brain_body_analysis brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin', 'session_secret': 'c5a595fd54e994cc0d155227812d91bf'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=ma53kVIMdg8mYut7CwBK4gEb&client_secret=pDPp8fBGcGXZGVfF2b4TPPGpVdKPXxyf'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#2.对相关人体关键点进行检测，获得具体情况"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'person_num': 1, 'person_info': [{'body_parts': {'left_hip': {'y': 1052.333984375, 'x': 678.279296875, 'score': 0.8580613732337952}, 'top_head': {'y': 649.423828125, 'x': 727.615234375, 'score': 0.8717586398124695}, 'right_mouth_corner': {'y': 723.427734375, 'x': 686.501953125, 'score': 0.8974248766899109}, 'neck': {'y': 764.541015625, 'x': 711.169921875, 'score': 0.8832433223724365}, 'left_shoulder': {'y': 822.099609375, 'x': 785.173828125, 'score': 0.8967307806015015}, 'left_knee': {'y': 1233.232421875, 'x': 637.166015625, 'score': 0.8052977323532104}, 'left_ankle': {'y': 1397.685546875, 'x': 587.830078125, 'score': 0.7701303958892822}, 'left_mouth_corner': {'y': 723.427734375, 'x': 711.169921875, 'score': 0.9000952839851379}, 'right_elbow': {'y': 904.326171875, 'x': 587.830078125, 'score': 0.8087823390960693}, 'right_ear': {'y': 698.759765625, 'x': 678.279296875, 'score': 0.8625400066375732}, 'nose': {'y': 706.982421875, 'x': 694.724609375, 'score': 0.8883284330368042}, 'left_eye': {'y': 690.537109375, 'x': 719.392578125, 'score': 0.8910861015319824}, 'right_eye': {'y': 690.537109375, 'x': 694.724609375, 'score': 0.876572847366333}, 'right_hip': {'y': 1027.666015625, 'x': 596.052734375, 'score': 0.8580269813537598}, 'left_wrist': {'y': 1019.443359375, 'x': 719.392578125, 'score': 0.7875721454620361}, 'left_ear': {'y': 706.982421875, 'x': 752.283203125, 'score': 0.8997544050216675}, 'left_elbow': {'y': 945.439453125, 'x': 776.951171875, 'score': 0.8304708003997803}, 'right_shoulder': {'y': 780.986328125, 'x': 628.943359375, 'score': 0.8382964730262756}, 'right_ankle': {'y': 1307.236328125, 'x': 596.052734375, 'score': 0.7877513766288757}, 'right_knee': {'y': 1142.783203125, 'x': 513.826171875, 'score': 0.842321515083313}, 'right_wrist': {'y': 986.552734375, 'x': 587.830078125, 'score': 0.6717200875282288}}, 'location': {'height': 841.8361206054688, 'width': 328.5526123046875, 'top': 619.5653076171875, 'score': 0.9984216690063477, 'left': 485.7120361328125}}], 'log_id': 2092801437936247797}\n"
     ]
    }
   ],
   "source": [
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "人体关键点识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/body_analysis\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('D:/360Downloads/2.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.bf5bbb6757ed8399c279b09bfae5ba54.2592000.1613800038.282335-23570374'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
